package java_14;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/*
把1-10000以内的所有质数，写入文件中，每20个一行
*/
public class Test_3 {
    public static void main(String[] args) {
        int count=0;
        BufferedWriter b=null;
        for (int i=1;i<=10000;i++){
            int b1=0;
            for (int j=1;j<=i;j++) {
                if (i % j == 0) {
                    b1++;
                }
            }
                if (b1 == 2){
                    try {
                        b = new BufferedWriter(new FileWriter("D:\\第一小组\\zpc.txt"));
                        count++;
                        String s=i+" ";
                        b.write(s);
                        b1=0;
                        if (count % 20 == 0) {
                            b.newLine();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        try {
                            b.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }

            }
        }
    }
}
